<?php

/**
 * do search 
 *
 * @author Jensen
 */
class search extends AbstractAction {

    public function run() {
        global $TPL;
        $page = intval($_GET['p']);
        if (empty($page)) {
            $page = 1;
        }

        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $keyword = cleanInput($_POST['keyword']);
        } else if ($_SERVER['REQUEST_METHOD'] == 'GET') {
            $keyword = cleanInput($_GET['keyword']);
        }


        $itemDAO = new BTItemsDAO();
        $result = $itemDAO->DoSearch($keyword, PERPAGE, $page);

        // pager information

        if (debug) {
            $pager = new Pager('index.php?action=search&keyword=' . $keyword, $result['count'], PERPAGE, $page, 'p');
        } else {
            $pager = new Pager(__CLASS__ . '?keyword=' . $keyword, $result['count'], PERPAGE, $page, 'p');
        }

        $TPL->assign('keyword', $keyword);
        $TPL->assign('items', $result['items']);
        $TPL->assign('totalcount', $result['count']);
        $TPL->assign('pager', $pager->getBar());
        $TPL->display('search.tpl');
    }

}

?>
